<template>
  <el-row class="row-header">
    <div class="hearder-header">
      <ul class="ul-header">
        <li class="li-header">推荐民宿</li>
        <li class="title-header activte" @mouseenter="onmouseenter" ref="activelis">{{$store.state.geo.position.city.replace('市','')}}</li>
        <li class="title-header" v-for="item in hotCity" :key="item" @mouseenter="onmouseenter" ref="activeli">{{item}}</li>
        <li class="more-header"><a style="color: #fff" href="https://minsu.meituan.com?phx_wake_up_type=mtpc_category&phx_wake_up_source=recommend">全部></a></li>
      </ul>
    </div>
    <div class="row-content">
      <div class="wrapper-h">
        <Hetel v-for="(item, index) in hotel" :key="index" :hotel="item"></Hetel>
      </div>
    </div>
  </el-row>
</template>
<script>
import Hetel from '../../com/hotel'
export default {
  data () {
    return {
      isactive: false
    }
  },
  components: {
    Hetel
  },
  computed: {
    hotCity() {
      let ret = []
      this.$store.state.geo.hotCity.forEach(item => {
        ret.push(item)
      })
      let nowcity = this.$store.state.geo.position.city
      let index = ret.indexOf(nowcity)
      if (index != -1) {
        ret.splice(index,1)
      }
      return ret.map(item => {
        return item.replace('市','')
      })
    },
    hotel () {
      let ret = this.$store.state.home.InithotelList.map((item) => {
        if (item.photos.length) {
          return {
            img: item.photos[0].url,
            title: item.name,
            position: item.adname,
            address: item.address,
            price: item.biz_ext.cost.length ? item.biz_ext.cost[0] : '暂无报价'
          }
        }
      })
      return ret.splice(0,6)
    }
  },
  methods: {
    async onmouseenter(e) {
      this.$refs.activeli.forEach(item => {
        item.className = 'title-header'
      })
      let city = e.target.innerHTML
      this.$refs.activelis.className = 'title-header'
      e.target.className = 'title-header activte'
      let {status, data:{pois}} = await this.$axios.get('http://localhost:3200/search/resultsByKeywords', {
        params: {
          city,
          keyword: '酒店'
        }
      })
      if (status===200) {
        this.$store.commit('home/setInithotelList',pois)
      }

    }
  }
}
</script>
<style scoped lang="scss">
  .row-header{
    padding-left: 20px;
    margin-top: 40px;
  }
  .hearder-header{
    width: 100%;
    height: 44px;
    background: linear-gradient(to right, rgb(243, 182, 74) 2%, rgb(242, 197, 69) 97%) rgb(243, 182, 74);
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
  }
  .ul-header{
    color: #fff;
    line-height: 44px;
    li {
      list-style: none;
      margin-left: 5px;
      margin-right: 5px;
      float: left;
      position: relative;
      cursor: pointer;
    }
  }
  .li-header{
    font-size: 18px;
    cursor: none;
    margin-left: 20px !important;
    margin-right: 15px !important;
  }
  .activte{
    &:after{
      position: absolute;
      content: "";
      border-left: 5px solid transparent;
      border-bottom: 7px solid #fff;
      border-right: 5px solid transparent;
      display: block;
      width: 2px;
      top: 37px;
      right: 0;
      left: 0;
      margin: auto;
    }
  }
  .title-header{
    font-size: 14px;
  }
  .more-header {
    font-size: 14px;
    float: right !important;
    padding-right: 5px;
    margin-right: 20px;
  }
  .row-content{
    border: 1px solid #E5E5E5;
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    border-top: none;
    padding-top: 5px;
    box-sizing: border-box;
  }
  .wrapper-h{
    width: 100%;
    display: flex;
    flex: 1;
    flex-wrap: wrap;
  }
</style>
